<template>
  <div>
    <div>Tom: {{ count }}</div>
    <button @click="addJerry"> + 1</button>
    <div>mapState: {{ tomCount }}, {{ jerryCount }}</div>
    <button @click="onClickMapbtn">onClickMapbtn</button>
  </div>
</template>

<script>
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'
export default {
  data() {
    return {
    }
  },
  computed: {
    count() {
      return this.$store.state.tomCount
    },

    ...mapState(['tomCount', 'jerryCount']),
    /*
    等效于：
    tomCount() {
      return this.$store.state.tomCount
    },
    jerryCount() {
      return this.$store.state.jerryCount
    }
    */

    ...mapGetters(['showJerryCount'])

  },
  methods: {
    addJerry() {
      this.$store.commit('addJerry', 1)
    },

    ...mapMutations(['addJerry']),
    onClickMapbtn() {
      this.addJerry(88)
    },

    ...mapActions(['addTomAsync'])

  }
}
</script>

<style>

</style>
